<?php

// start session
session_start();

// connect to database
$conn_str = 'host=dbsrv1.cdf.toronto.edu dbname=csc309g23 user=csc309g23 password=ipheid5h';
$conn = pg_connect($conn_str);

// query database
$query = 'INSERT INTO rosters (username,gameid,organizer,status,team) VALUES (\'' . $_SESSION['username'] . '\', ' . $_POST['gameid'] . ', \'f\', 0,  ' . $_POST['team'] . ')';

if ($result = pg_query($conn, $query)) { // if succesfully update roster record - i.e accepted invite
    // go back to page from which user logged in
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
    echo $query;
}
?>